##########################################################################
###  Replication Files for "The Unintended Consequences of Arms Embargoes"
###  Code for Figures
##########################################################################

#  Load Libraries
library(tidyverse)

###  Figure 1:  TIVs of Embargoed versus Non-Embargoed Countries
#  Load Data
data <- read.csv("tiv plot.csv", header=T)

#  Plot
ggplot(data, aes(var, tiv, fill=embargoed)) +
  geom_bar(stat="identity", position=position_dodge()) +
  theme(legend.title = element_blank()) +
  labs(x = "Embargo Type", y = "TIV", color = "Embargo Status")


###  Figure 2, Left-Hand Side
#  Load Data
tiv <- read.csv("tiv_compare.csv", header=T)

#  Plot
ggplot(tiv, aes(x=reorder(name, ratio), y=ratio)) +
  geom_bar(stat="identity", fill="steelblue", color="black") +
  coord_flip() +
  xlab("Country") + ylab("Ratio of TIV Receipt to TIV Supply")

###  Figure 2, Right-Hand Side
#  Load Data
sales <- read.csv("ratio_sales.csv", header=T)

#  Plot
ggplot(sales, aes(x=reorder(name, ratio), y=ratio)) +
  geom_bar(stat="identity", fill="steelblue", color="black") +
  coord_flip() +
  xlab("Country") + ylab("Ratio of Purchases to Sales")


###  Figure 3
#  Load Data
orig <- read.csv("origin_compare.csv", header=T)

#  Plot
ggplot(orig, aes(x=reorder(name, ratio), y=ratio)) +
  geom_bar(stat="identity", fill="steelblue", color="black") +
  coord_flip() +
  xlab("Country") + ylab("Ratio of Purchases to Sales")


###  Figure 4:  Types of Weapons Transferred, by Embargo Status
#  Load Data
data <- read.csv("type plot 1-22.csv", header=T)

#  Plot
ggplot(data, aes(type, value_no_ngf, fill=embarg)) +
  geom_bar(stat="identity", position=position_dodge()) +
  theme(legend.title = element_blank()) +
  labs(x = "Percent of Total Transfers", y = "Weapon Type", color = "Embargo Status")


###  Figure 5: Transfers of New, Secondhand, and Refurbished Systems, by Embargo Status
#  Load Data
data <- read.csv("status plot 1-22.csv", header=T)

#  Plot
ggplot(data, aes(status, value_no_ngf, fill=embarg)) +
  geom_bar(stat="identity", position=position_dodge()) +
  theme(legend.title = element_blank()) +
  labs(x = "Percent of Total Transfers", y = "Weapon Status", color = "Embargo Status")


###  Figure 6:  Direct versus Middleman Transfers, by Embargo Status
#  Load Data
data <- read.csv("middle compare.csv", header=T)

#  Plot
ggplot(data, aes(x = type, y = value_no_ngf, fill=state)) +
  geom_bar(stat="identity", position=position_dodge()) +
  # theme(legend.title = element_blank()) +
  scale_fill_discrete(name = "Embargo Status") +
  labs(x = "Source of Transfer", y = "Percent of Total Transfers")